package com.dycx.message.converter;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dycx.message.dto.VerificationCodeDTO;
import com.dycx.message.entity.VerificationCodeDO;
import com.dycx.message.vo.VerificationCodeVO;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 验证码(VerificationCode)实体转换类
 *
 * @author wuzongbin
 * @since 2024-01-12 10:39:27
 */


@Data
public class VerificationCodeConverter implements Serializable {
    public static VerificationCodeDO dtoToEntity(VerificationCodeDTO dto) {
        if (dto == null) return null;
        VerificationCodeDO entity = BeanUtil.toBean(dto, VerificationCodeDO.class);
        return entity;
    }

    public static VerificationCodeVO entityToVo(VerificationCodeDO entity) {
        if (entity == null) return null;
        VerificationCodeVO vo = BeanUtil.toBean(entity, VerificationCodeVO.class);

        return vo;
    }

    public static List<VerificationCodeVO> entityToVoList(List<VerificationCodeDO> entityList) {
        List<VerificationCodeVO> voList = new ArrayList<>();
        for (VerificationCodeDO entity : entityList) {
            voList.add(entityToVo(entity));
        }
        return voList;
    }

    public static Page<VerificationCodeVO> entityToVoPage(Page<VerificationCodeDO> page) {

        List<VerificationCodeVO> newRecords = new ArrayList<>();

        List<VerificationCodeDO> records = page.getRecords();
        for (VerificationCodeDO entity : records) {
            newRecords.add(entityToVo(entity));
        }

        Page<VerificationCodeVO> voPage = new Page<>();
        voPage.setRecords(newRecords);
        voPage.setPages(page.getPages());
        voPage.setTotal(page.getTotal());
        voPage.setSize(page.getSize());
        voPage.setCurrent(page.getCurrent());

        return voPage;
    }

}
